package com.lanswon.qzsmk.controller.cardManageController;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.base.DwzPage;
import com.lanswon.qzsmk.base.PathContants;
import com.lanswon.qzsmk.model.CardNoGenerated;
import com.lanswon.qzsmk.service.cardManageService.BanckCardBusinessService;
import com.lanswon.qzsmk.service.cardManageService.MakeCardService;
import com.lanswon.qzsmk.util.CitizenCardNoGeneratorUtil;
import com.lanswon.qzsmk.vo.CardNoGeneratedVo;

/**
 * 自主发卡卡号库controller
 * @author GU-YW
 *
 */
@Controller
@RequestMapping("/generateCardNo")
public class GenerateCardNoController {
	
	@Autowired
	MakeCardService makeCardService;
	
	@RequestMapping(value="/index",name="查询自主发卡卡号库生成记录,generateCardNo:index")
	@RequiresPermissions("generateCardNo:index")
	public String index(){
		return "AutonomyGenerateCardNoDetail";
	}
	
	@RequestMapping(value="/goGenerateCardNumber",name="自主发卡生成卡号库,generateCardNo:goGenerateCardNumber")
	@RequiresPermissions("generateCardNo:goGenerateCardNumber")
	public String goGenerateCardNumber(){
		return "AutonomyGenerateCardNo";
	}
	
	@RequiresPermissions("generateCardNo:queryAuotnomyCardNoDetail")
	@RequestMapping(value="/queryCardNoDetail",name="查询自主发卡卡卡号库生成记录,generateCardNo:queryAuotnomyCardNoDetail",method=RequestMethod.POST)
	@ResponseBody
	public DwzPage<CardNoGeneratedVo> queryAuotnomyCardNoDetail(CardNoGeneratedVo vo, Integer pageNum,Integer numPerPage){
		if(pageNum==null&&numPerPage==null){
			pageNum=1;
			numPerPage=20;	
		}
		vo.setCurrentPage(pageNum);
		vo.setNumPerPage(numPerPage);
		vo.setStartLine((vo.getCurrentPage()-1)*vo.getNumPerPage());
		DwzPage<CardNoGeneratedVo> dPage=makeCardService.queryCardNoDetail(vo);
		return dPage;
	}
	
	@RequiresPermissions("generateCardNo:generateCardNumber")
	@RequestMapping(value="/generateCardNumber",name="自主发卡生成卡号,generateCardNo:generateCardNumber",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object>  generateCardNumber(String cardPCode,String cardPhysicalType,String cardNoNUm,HttpServletResponse response) throws NumberFormatException, Exception{
		Map<String, Object>map=new HashMap<>();
		String prefix = CitizenCardNoGeneratorUtil.getCardNoPrefix(cardPCode, cardPhysicalType);
		Boolean f=makeCardService.generatorCitizenCardNo(cardPCode,prefix, Integer.valueOf(cardNoNUm));
		if(f) {
			map.put("statusCode", 200);
			map.put("message", PathContants.FTP_URL+PathContants.FTP_PATH_CARDNOAUTONOMY);
		}
		else {
			map.put("statusCode", 300);
			map.put("message", "生成卡号上传ftp失败");
		}
		return map;
	}
}
